package com.chushouya.product.service.api.impl;

import com.chushouya.common.dto.suhuishou.ResponseDTO;
import com.chushouya.common.util.SuhuishouRequest;
import com.general.framework.core.lang.Jsons;
import com.chushouya.product.dto.api.suhuishou.SuhuishouBrandDTO;
import com.chushouya.product.dto.api.suhuishou.SuhuishouEvaluateResultDTO;
import com.chushouya.product.dto.api.suhuishou.SuhuishouProductDTO;
import com.chushouya.product.dto.api.suhuishou.SuhuishouProductListDTO;
import com.chushouya.product.service.api.SuhuishouProductApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.chushouya.common.constant.SuhuishouConstants.*;


/**
 * @author wangweibo
 */
@Slf4j
@Service
public class SuhuishouProductApiServiceImpl implements SuhuishouProductApiService {

    @Resource
    private SuhuishouRequest suhuishouRequest;

    private static final String[] FILTER_WORDS = {"全新","无法开机"};

    @Override
    public SuhuishouProductDTO requestProductData(Long id) {
        final Map<String, Object> params = new HashMap<>();
        params.put("productId", id);
        ResponseDTO<SuhuishouProductDTO> response = suhuishouRequest.httpRequest(SUHUISHOU_EVALUATE_PRODUCT,"GET",params,SuhuishouProductDTO.class);
        log.info("requestProductData response:{}", response);
        return response.getData();
    }

    @Override
    public List<SuhuishouBrandDTO> requestBrandList(Long categoryId) {
        final Map<String, Object> params = new HashMap<>();
        params.put("categoryId", categoryId);
        ResponseDTO<List> response = suhuishouRequest.httpRequest(SUHUISHOU_BRAND_LIST,"GET",params,List.class);
        return Jsons.parseArray(response.getData().toString(), SuhuishouBrandDTO.class);
    }

    @Override
    public SuhuishouProductListDTO requestProductList(Long categoryId, Long brandId) {
        final Map<String, Object> params = new HashMap<>();
        params.put("categoryId", categoryId);
        params.put("brandId", brandId);
        params.put("page", 1);
        params.put("size", 200);
        ResponseDTO<SuhuishouProductListDTO> response = suhuishouRequest.httpRequest(SUHUISHOU_PRODUCT_LIST,"GET",params,SuhuishouProductListDTO.class);
        log.info("response:{}",response);
        return response.getData();
    }

    @Override
    public SuhuishouEvaluateResultDTO requestEvaluateData(Long id, String attrId) {
        final Map<String, Object> params = new HashMap<>();
        params.put("productId", id);
        params.put("skuCode", attrId);
        params.put("skuId", "");
        params.put("evaluateCode", "");
        ResponseDTO<SuhuishouEvaluateResultDTO> response = suhuishouRequest.httpRequest(SUHUISHOU_EVALUATE_RESULT,"POST",params, SuhuishouEvaluateResultDTO.class);
        log.info("requestEvaluateData response:{}", response);
        return response.getData();
    }


}
